<?php

namespace Admin\Controller;

use Think\Controller;
use Think\Verify;

/**
 * 管理帐号登陆操作类
 * Class LoginController
 * @package Admin\Controller
 */
class LoginController extends Controller
{
    /**
     * 登陆操作
     */
    public function index()
    {
        if (IS_POST) {
            //1.管理员账户//
               $adminModel = D('Admin');
            if ($adminModel->validate($adminModel->_login_validate)->create($_POST, 6)) {

            if ($adminModel->doLogin()) {
               // echo 'wqewq ewq';
               redirect(U('Admin/Index/index'));
              }
            }
            //2.分级用户，从user中查找
             $this->error($adminModel->getError());
        }
        $this->display();
    }

    /**
     * 生成验证码图片
     */
    public function chkcode()
    {
        ob_end_clean();
        $Verify = new Verify(array(
            'length' => 4,
            'useNoise' => FALSE,
            'codeSet' => '0123456789',
            'imageH' => 40,
            'imageW' => 140,
            'fontSize' => 20
        ));
        $Verify->entry();
    }

    /**
     * 退出操作
     */
    Public function logout()
    {
        session_unset();
        session_destroy();
        redirect(U('Admin/Login/index'));
    }
}